package neusoft.yuejian_11.model;


import java.util.List;

import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.AddPrize;
import neusoft.yuejian_11.bean.AddfeedBean;
import neusoft.yuejian_11.bean.AddpostBean;
import neusoft.yuejian_11.bean.ClubInformBean;
import neusoft.yuejian_11.bean.DuijiangBean;
import neusoft.yuejian_11.bean.GetInfo;
import neusoft.yuejian_11.bean.InformBean;
import neusoft.yuejian_11.bean.IsAddPrize;
import neusoft.yuejian_11.bean.IsAttentionBean;
import neusoft.yuejian_11.bean.PostBean;
import neusoft.yuejian_11.bean.PrizeBean;
import neusoft.yuejian_11.bean.RegBean;
import neusoft.yuejian_11.bean.SampleInfo;
import neusoft.yuejian_11.bean.SampleLogin;
import neusoft.yuejian_11.interF.AttentionService;
import neusoft.yuejian_11.interF.Const;
import neusoft.yuejian_11.interF.RetrofitService;
import neusoft.yuejian_11.listener.RetrofitListener;
import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by NEUSOFT on 2017/9/26.
 */

public class UserModel extends BaseActivity{
    private Retrofit retrofit;
    public UserModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
   //用户登录
    public void login(String editText_user, String editText_pass,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call= retrofitService.getUserLogin(editText_user,editText_pass);
        call.enqueue(new Callback<SampleLogin>() {
            @Override
            public void onResponse(Call<SampleLogin> call, Response<SampleLogin> response) {
                SampleLogin sampleLogin=response.body();
                listener.onSuccess(sampleLogin,1);
            }
            @Override
            public void onFailure(Call<SampleLogin> call, Throwable t) {
                listener.onFail();
            }
        });
    }



    //用户注册
    public void register(String userName, String password1R, String userPhone, String userEmail, String userAddress,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.getuserRegister(userName,password1R,userPhone,userEmail,userAddress);
        call.enqueue(new Callback<RegBean>() {
            @Override
            public void onResponse(Call<RegBean> call, Response<RegBean> response) {
                RegBean regBean=response.body();
                listener.onSuccess(regBean,1);
            }
            @Override
            public void onFailure(Call<RegBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }

   //获取个人信息
    public void getUserInfo(int u_id,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.getUserInfo(getU_id());
        call.enqueue(new Callback<GetInfo>() {
            @Override
            public void onResponse(Call<GetInfo> call, Response<GetInfo> response) {
                GetInfo getInfo=response.body();
                listener.onSuccess(getInfo,2);
            }
            @Override
            public void onFailure(Call<GetInfo> call, Throwable t) {
                listener.onFail();
            }
        });
    }


    //修改个人信息
    public void updateUserById(int u_id, String u_name, String u_pass, String u_phone, String u_address, String u_email,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call=retrofitService.updateUserById(getU_id(),u_name,u_pass,u_phone,u_address,u_email);
        call.enqueue(new Callback<SampleInfo>() {
            @Override
            public void onResponse(Call<SampleInfo> call, Response<SampleInfo> response) {
                SampleInfo sampleInfo=response.body();
                listener.onSuccess(sampleInfo,3);
            }
            @Override
            public void onFailure(Call<SampleInfo> call, Throwable t) {
                listener.onFail();
            }
        });
    }

    //所有奖品列表
    public void  Prizelist(final RetrofitListener listener){
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<PrizeBean>> call = retrofitService.getPrizelist();
        Callback<List<PrizeBean>> callback = new Callback<List<PrizeBean>>() {
            @Override
            public void onResponse(Call<List<PrizeBean>> call, Response<List<PrizeBean>> response) {
                List<PrizeBean> prizeBean = response.body();
                listener.onSuccess(prizeBean,1);
            }
            @Override
            public void onFailure(Call<List<PrizeBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //获取奖品详情
    public void PrizeByIdDetail(String giftId,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.getPrizeById(String.valueOf(giftId));
        call.enqueue(new Callback<PrizeBean>() {
            @Override
            public void onResponse(Call<PrizeBean> call, Response<PrizeBean> response) {
                PrizeBean prizeBean=response.body();
                listener.onSuccess(prizeBean,1);
            }
            @Override
            public void onFailure(Call<PrizeBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }


    //获取系统通知列表
    public void  getInformlist(final RetrofitListener listener){
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<InformBean>> call = retrofitService.getInformlist();
        Callback<List<InformBean>> callback = new Callback<List<InformBean>>() {
            @Override
            public void onResponse(Call<List<InformBean>> call, Response<List<InformBean>> response) {
                List<InformBean> informBean = response.body();
                listener.onSuccess(informBean,1);
            }
            @Override
            public void onFailure(Call<List<InformBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }


     //获取俱乐部通知列表
     public void  getCInformlist(final RetrofitListener listener){
         RetrofitService retrofitService = retrofit.create(RetrofitService.class);
         Call<List<ClubInformBean>> call = retrofitService.getCInformlist();
         Callback<List<ClubInformBean>> callback = new Callback<List<ClubInformBean>>() {
             @Override
             public void onResponse(Call<List<ClubInformBean>> call, Response<List<ClubInformBean>> response) {
                 List<ClubInformBean> clubInformBean = response.body();
                 listener.onSuccess(clubInformBean,1);
             }
             @Override
             public void onFailure(Call<List<ClubInformBean>> call, Throwable t) {
                 listener.onFail();
             }
         };
         call.enqueue(callback);
     }


    //获取我的帖子列表
    public void getMyPost(int u_id,final RetrofitListener listener) {
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<PostBean>> call = retrofitService.getMyPost(getU_id());
        call.enqueue(new Callback<List<PostBean>>() {
            @Override
            public void onResponse(Call<List<PostBean>> call, Response<List<PostBean>> response) {
                List<PostBean> postBean = response.body();
                listener.onSuccess(postBean, 1);
            }
            @Override
            public void onFailure(Call<List<PostBean>> call, Throwable t) {
            }
        });
    }


    //获取我的兑奖列表
    public void getMyDuijiang(int u_id,final RetrofitListener listener) {
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<DuijiangBean>> call=retrofitService.getMyDuijiang(getU_id());
        call.enqueue(new Callback<List<DuijiangBean>>() {
            @Override
            public void onResponse(Call<List<DuijiangBean>> call, Response<List<DuijiangBean>> response) {
                List<DuijiangBean> duijiangBean = response.body();
                listener.onSuccess(duijiangBean, 1);
            }
            @Override
            public void onFailure(Call<List<DuijiangBean>> call, Throwable t) {
            }
        });
    }

        //添加反馈信息
        public void addfeedback(int u_id,String phone, String content,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.addfeedback(getU_id(),phone,content);
        call.enqueue(new Callback<AddfeedBean>() {
            @Override
            public void onResponse(Call<AddfeedBean> call, Response<AddfeedBean> response) {
                AddfeedBean addfeedBean=response.body();
                listener.onSuccess(addfeedBean,1);
            }
            @Override
            public void onFailure(Call<AddfeedBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }



    //判断奖品是否已经被兑换过
    public void IsAddPrize(String u_id, String g_id,final RetrofitListener listener) {
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call call=retrofitService.IsAddPrize(String.valueOf(u_id),String.valueOf(g_id));
        call.enqueue(new Callback<IsAddPrize>() {
            @Override
            public void onResponse(Call<IsAddPrize> call, Response<IsAddPrize> response) {
                IsAddPrize isAddPrize=response.body();
                listener.onSuccess(isAddPrize,4);
            }
            @Override
            public void onFailure(Call<IsAddPrize> call, Throwable t) {

            }
        });
    }

    //添加兑奖信息
    public void addPrize(int u_id,String giftId,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.addprize(getU_id(), String.valueOf(giftId));
        call.enqueue(new Callback<AddPrize>() {
            @Override
            public void onResponse(Call<AddPrize> call, Response<AddPrize> response) {
                AddPrize addPrize=response.body();
                listener.onSuccess(addPrize,3);
            }
            @Override
            public void onFailure(Call<AddPrize> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //修改用户头像
    public Call<AddpostBean>  updatetouxiang(int u_id, MultipartBody.Part file)  {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        return retrofitService.updatetouxiang(u_id,file);
    }

}
